define(function (require) {
    'use strict';
    return {
        controller: function (so, dialog, iptvService, location) {
            var self = this;
            console.log(require('service/MenuConfig'));
            this.so = so;
            this.dialog = dialog;
            this.TUZi = iptvService;
            this.location = location;
            so.logoText = $.i18n.text('logo_text');
            so.switchDisplayMode = function () {
                so.isShow = !so.isShow;
            };
            so.chooseMenu = function (currentMenuText) {
                so.subMenuTitle = currentMenuText;
            };
            so.login = function ($element) {
                console.log($element);
            };
            so.isShow = true;
            self.init();
        },
        init: function () {
            var self = this;
            this.TUZi.getMenuRequest().success(function (menuData) {
                var menuList = menuData.menuData;
                self.so.menuList = menuList;
                self.showMenuList(menuList);
                self.so.$on('$stateChangeSuccess', function () {
                    self.showMenuList(menuList);
                });

            });
        },
        showMenuList: function (menuList) {
            var currentNumber = this.location.path().split('/')[2];
            this.so.isShow = true;
            this.so.isExsited = true;
            if (!!currentNumber) {
                var menuTarget = _.filter(menuList, function (resp) {
                    return resp.menuNo === parseInt(currentNumber);
                });
                this.so.currentMenuText = menuTarget[0].menuText;
                if (menuTarget[0].subMenuList.length === 0) {
                    this.so.isExsited = false;
                }
                this.so.subMenuList = menuTarget[0].subMenuList;
            } else {
                this.so.currentMenuText = menuList[0].menuText;
                this.so.subMenuList = menuList[0].subMenuList;
            }
        }
    }
});
